package org.dromara.system.controller.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.DeviceGroup;
import org.dromara.system.domain.SysSystem;
import org.dromara.system.domain.bo.ReportChartBo;
import org.dromara.system.domain.bo.ResponsibleDeviceBo;
import org.dromara.system.domain.pojo.ReportChart;
import org.dromara.system.domain.vo.*;
import org.dromara.system.mapper.DeviceAlarmMapper;
import org.dromara.system.mapper.DeviceGroupMapper;
import org.dromara.system.service.IDeviceAlarmService;
import org.dromara.system.service.IDeviceService;
import org.dromara.system.service.ISysSystemReportService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备报警
 *
 * @author Lion Li
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/dashBroad")
public class DashBroadController extends BaseController {

    private final IDeviceService deviceService;

    private final ISysSystemReportService sysSystemReportService;
    private final IDeviceAlarmService deviceAlarmService;

    @SaCheckPermission("system:device:list")
    @GetMapping("/index")
    public R<DashVo> dashBroad() {
        return R.ok(deviceService.dashBroad());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getStatistics")
    public R<StatisticsVo> statistics() {
        Long userId = LoginHelper.getUserId();
        return R.ok(deviceService.statistics(userId));
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getResponsibleDevice")
    @Log(title = "获取当前用户下责任设备", businessType = BusinessType.OTHER)
    public R<TableDataInfo<DeviceCollectListVo>> getResponsibleDevice(ResponsibleDeviceBo bo, PageQuery pageQuery) {
        return R.ok(deviceService.getResponsibleDevice(bo, pageQuery));
    }


    @SaCheckPermission("system:device:list")
    @GetMapping("/getDataSource")
    @Log(title = "获取当前系统下数据源状态", businessType = BusinessType.OTHER)
    public R<List<SysSystem>> getDataSource() {
        return R.ok(deviceService.getDataSource());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getDeviceChart/{id}")
    @Log(title = "获取系统设备饼图", businessType = BusinessType.OTHER)
    public R<List<StatisticsDeviceVo>> getDeviceChart(@PathVariable("id") Long id) {
        return R.ok(deviceService.getDeviceChart(id));
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getReportChar")
    @Log(title = "昨日运行报告-报警列表", businessType = BusinessType.OTHER)
    public R<List<ReportChart>> reportChart(ReportChartBo bo) {
        return R.ok(sysSystemReportService.getReportChart(bo));
    }


    @SaCheckPermission("system:device:list")
    @GetMapping("/getReportNum")
    @Log(title = "昨日运行报告", businessType = BusinessType.OTHER)
    public R<DataVo> getReportNum() {
        return R.ok(sysSystemReportService.getReportNum());
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getReportInfo")
    @Log(title = "昨日运行报告-统计", businessType = BusinessType.OTHER)
    public R<DashVo> getReportInfo(ReportChartBo bo) {
        return R.ok(sysSystemReportService.getReportInfo(bo));
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getReportAlarm")
    @Log(title = "昨日运行报告-报警列表", businessType = BusinessType.OTHER)
    public TableDataInfo<DeviceAlarmVo> getReportAlarm(ReportChartBo bo, PageQuery pageQuery) {
        return sysSystemReportService.getReportAlarm(bo, pageQuery);
    }

    @SaCheckPermission("system:device:list")
    @GetMapping("/getReportLogList")
    @Log(title = "昨日运行报告-报警列表", businessType = BusinessType.OTHER)
    public TableDataInfo<SysSystemReportVo> getReportLogList(ReportChartBo bo, PageQuery pageQuery) {
        return sysSystemReportService.getReportLogList(bo, pageQuery);
    }


}
